import React from 'react'

export default class Hello extends React.Component {
    constructor() {
        super()
        this.state = {
            msg: '今天天气真不错',
            id: ''
        }

    }
    render() {
        return <div>
            <button onClick={() => this.start()}>点我啊</button>
            <button onClick={() => this.stop()}>暂停</button>
            <br />
            {this.state.msg}
        </div>
    }
    start = () => {
        if (this.state.id != '') return
        const count = setInterval(() => {
            const str = this.state.msg
            const end = str.substring(str.length - 1)
            const start = str.substring(0, str.length - 1)
            const newStr = end + start
            this.setState({
                msg: newStr,
                id: count
            })
        }, 500)
    }
    stop = () => {
        clearInterval(this.state.id)
        this.setState({
            id: ''
        })
    }
}